package com.geek.javase.ch02.test3;

/*
 *@author wangpeng
 *2025/10/10 13:20
 *@description TODO
 */
public class Person {
    private String name;
    private int age;
    private boolean gender;  // 性别 true男 false女
    private Person partner;  // 伴侣

    // 构造方法
    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.partner = null;
    }

    // getter和setter方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isGender() {
        return gender;
    }

    public void setGender(boolean gender) {
        this.gender = gender;
    }

    public Person getPartner() {
        return partner;
    }

    // marry方法：处理结婚逻辑
    public void marry(Person p) {
        // 检查是否为同性
        if (this.gender == p.gender) {
            System.out.println("不能结婚：同性不能结婚");
            return;
        }

        // 检查年龄是否符合要求
        if ((this.gender && this.age < 24) || (!this.gender && this.age < 22)) {
            System.out.println(this.name + "不能结婚：未达到结婚年龄");
            return;
        }

        if ((p.gender && p.age < 24) || (!p.gender && p.age < 22)) {
            System.out.println(p.name + "不能结婚：未达到结婚年龄");
            return;
        }

        // 检查是否已婚
        if (this.partner != null) {
            System.out.println(this.name + "不能结婚：已婚");
            return;
        }

        if (p.partner != null) {
            System.out.println(p.name + "不能结婚：已婚");
            return;
        }

        // 可以结婚
        this.partner = p;
        p.partner = this;
        System.out.println("恭喜" + this.name + "和" + p.name + "结婚成功！");
    }
}
